home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9134 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  61 lines

  1. Path: columba.udac.uu.se!not-for-mail
  2. From: trulsson@student.docs.uu.se (Erik Trulsson)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: C/C++ cross-platform compatibility
  5. Date: 7 Mar 1996 17:52:23 GMT
  6. Organization: Uppsala Universitet
  7. Message-ID: <4hn7on$1ttc@columba.udac.uu.se>
  8. References: <4hfvlk$dn1@bay> <313BD1B0.40AB@ix.netcom.com>
  9. NNTP-Posting-Host: minsk.docs.uu.se
  10. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  11.  
  12. Henry Cross (hcross@ix.netcom.com) wrote:
  13. > charrick@netrover.com wrote:
  14. > > 
  15. > > I'm working on an application I want to compile on many
  16. > > different platforms.  Somewhere along the line, I need to
  17. > > obtain a list of all files in a directory.  In OS/2, DOS,
  18. > > WinNT, etc... the way to do this is with DosFindFirst and
  19. > > DosFindNext.  However, these are not part of the ANSI
  20. > > standard, so I want to know, what should I use?  Are these
  21. > > actually supported on everything, or is there another way
  22. > > to do this?
  23. >   I'm not a pro but I do believe this is an OS specific problem
  24. > that can't be solved by any current ANSI standard function.
  25.  
  26. This is indeed an OS-specific issue. There are no functions
  27. that are available on all , or even on most , platforms for getting
  28. the contents of a directory.
  29.  
  30. The only way should be to write wrapper functions that are conditionally
  31. compiled to call the right function(s).
  32. I.e. something like:
  33.  
  34. mygetdirlist(char *dirname)
  35. {
  36. #ifdef MSDOS
  37. DosFindFirst...
  38. ...
  39. #endif
  40.  
  41. #ifdef UNIX
  42. opendir(...)
  43. readdir(...)
  44. ...
  45. #endif
  46.  
  47. #ifdef AMIGA
  48. ....
  49. #endif
  50.  
  51. }
  52.  
  53. (The above certainly isn't correct code but the general idea should be clear)
  54.  
  55. Some support for directory manipulation should really be in the C Standard.
  56. (At least on those platforms that even support the concept of directories.
  57. (The vast majoirty of them that is. ))
  58.  
  59.